package com.daiqile.myinterest.fragement;


import android.net.http.SslError;
import android.support.v4.app.Fragment;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.daiqile.myinterest.BaseFragment;
import com.daiqile.myinterest.R;
import com.daiqile.myinterest.utils.WebViewManager;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class TwoFragment extends BaseFragment {
    @BindView(R.id.webView)
    WebView webView;
    private String url;

    public TwoFragment() {
        // Required empty public constructor
    }

    @Override
    protected int getContentView() {
        return R.layout.fragment_two;
    }

    @Override
    protected void initViews() {
        initWebView();
    }

    private void initWebView() {
        WebViewManager manager = new WebViewManager(webView);
        manager.enableAdaptive();
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                handler.proceed();
            }

            //使用该方法可以禁止唤醒淘宝的tbopen：
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.toString());
                return true;
            }
        });
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBlockNetworkImage(false);
        webView.setWebChromeClient(new WebChromeClient());//允许显示弹框
        url = "https://wapbaike.baidu.com/item/%E6%9D%8E%E7%9F%A5%E6%81%A9/74308?fromtitle=IU&fromid=12013444&fr=aladdin";
        webView.loadUrl(url);

    }

}
